<?php
/**
 * vr 图片播放器内容
 */
defined('IN_IA') or exit('Access Denied');
global $_GPC, $_W;
load()->func('tpl');
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$selects = $this->_forms;
$sec = $this->module_setting();
$uniacid = $_W['uniacid'];
$openid = $_W['openid'];
$tid = 13;
$child_tid = 14;
if($_GPC['child']> 0){
    $tid = $child_tid;
}

//默认列表
if($operation == 'display')
{
     if (!empty($_GPC['displayorder'])) {
        foreach ($_GPC['displayorder'] as $id => $displayorder) {
            pdo_update('kbwdl_house_saleinfo', array('orderid' => $displayorder), array('id' => $id, 'uniacid' => $_W['uniacid']));
        }
        message('排序更新成功！', $this->createWebUrl('article', array('op' => 'display')), 'success');
    }
    /*     * 分页显示 */
    $pindex = max(1, intval($_GPC['page']));
    $psize = 15;
    $status = $_GPC['status'];
   
    $condition = " o.uniacid = :uniacid and tid=:tid ";
    $paras = array(':uniacid' => $_W['uniacid'], ':tid'=> $tid);
    $sql = 'SELECT COUNT(*) FROM ' . tablename('kbwdl_house_saleinfo') . ' AS `o` WHERE ' . $condition;
    $total = pdo_fetchcolumn($sql, $paras);
    if ($total > 0) {
        if ($_GPC['export'] != 'export') {
            $limit = ' LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
        }
        $sql = 'SELECT * FROM ' . tablename('kbwdl_house_saleinfo') . ' AS `o` WHERE ' . $condition .
                ' ORDER BY `o`.`orderid` desc, `o`.`id` DESC ' . $limit;
        $list = pdo_fetchall($sql, $paras);
        $pager = pagination($total, $pindex, $psize);
    }   
 /**
     * 添加一个活动
     */
} elseif ($operation == 'post') {

    $selects['disabled'] = array('显示', '关闭');
    $id = intval($_GPC['id']);
    if (!empty($id)) {
        $info = pdo_fetch("SELECT * FROM " . tablename('kbwdl_house_saleinfo') . " WHERE tid=$tid and id = :id AND uniacid = :uniacid", array(':id' => $id, ':uniacid' => $_W['uniacid']));
        $info['newstext'] = iunserializer($info['newstext']);
        
    } else {
        $info = array(
            'disabled' => 0,
        );
    }
    if (checksubmit('submit')) {
        $data = $_GPC['data'];
      
        $data['newstext'] = iserializer($_GPC['thumb']);
        if (empty($data['title'])) {
            message('抱歉，请输入新闻名称！');
        }
        /*栏目信息*/
        $data['fid'] = 0;//intval($_GPC['fid']);
       // $data['fname'] =  tpdo_fetchcolumn("select name from ".tablename('site_category')." where id='".$data['fid']."'");
    
        if (!empty($id)) {
            pdo_update('kbwdl_house_saleinfo', $data, array('id' => $id, 'uniacid' => $_W['uniacid']));
           
        } else {
            $data['uniacid'] = $_W['uniacid'];
            $data['addtime'] =  date('Y-m-d H:i:s', TIMESTAMP);
            $data['tid'] = $tid; /**数据分类 活动*/
            pdo_insert('kbwdl_house_saleinfo', $data);
            $id = pdo_insertid();
        }
        message('更新信息成功', $this->createWebUrl('vrview', array('op' => 'display')), 'success');
    }
    /**
     * 删除一个记录
     */
} elseif ($operation == 'delete') {
    $id = intval($_GPC['id']);
    $category = pdo_fetch("SELECT id,title FROM " . tablename('kbwdl_house_saleinfo') . " WHERE id = '$id' and tid=$tid ");
    if (empty($category)) {
        message('抱歉，不存在或是已经被删除！', $this->createWebUrl('vrview', array('op' => 'display')), 'error');
    }
    pdo_delete('kbwdl_house_saleinfo', array('id' => $id, 'uniacid' => $_W['uniacid'], 'tid'=> $tid));
    message('删除成功！', $this->createWebUrl('vrview', array('op' => 'display')), 'success');

    
 /**
  * 添加栏目
  */  
}

include $this->template('vrview');

?>
